package com.joca.scheduling.pages;

import java.util.List;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;

import com.joca.scheduling.database.ScheduleData;
import com.joca.scheduling.entities.Role;
import com.joca.scheduling.entities.Schedule;
import com.joca.scheduling.entities.User;
import com.joca.scheduling.hibernateservices.UserServiceHibernate;

public class Professor {

	@SessionState(create = false)
	@Property
	private User user;
	private boolean userExists;

	@Persist
	private Schedule schedule;

	public Schedule getSchedule() {
		return schedule;
	}

	public void setSchedule(Schedule schedule) {
		this.schedule = schedule;
	}

	Object onActivate() {
		if (!userExists)
			return Index.class;
		if (user.getRole() == Role.Professor) {
			return null;
		}
		return Index.class;
	}

	public List<Schedule> getScheduleRequests() {
		return UserServiceHibernate.getUserServiceHibernate()
				.getSchedulesRequests(user);
		// return ScheduleData.getInstance().getSchedulesRequests(user);
	}

	public List<Schedule> getScheduleResponses() {
		// return ScheduleData.getInstance().getScheduleResponses(user);
		return UserServiceHibernate.getUserServiceHibernate()
				.getScheduleResponses(user);
	}

	public String getNames() {
		User u = UserServiceHibernate.getUserServiceHibernate().getUserByID(
				getSchedule().getScheduleRequest());
		return u.getName();

	}

	public String getSurnames() {
		User u = UserServiceHibernate.getUserServiceHibernate().getUserByID(
				getSchedule().getScheduleRequest());
		return u.getSurname();
	}

}
